﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace GiangDay
{
    class FunctionNghi
    {
        DB database = new DB();
        private SqlCommand cmd;
        DataTable dt;
        public DataTable danhsachlop()
        {
            database.Open();
            SqlDataAdapter adt = new SqlDataAdapter("SELECT * FROM LOP", database.conn);
            dt= new DataTable();
            adt.Fill(dt);
            database.Close();
            return dt;
        }
        public DataTable loadGiaovien()
        {
            database.Open();
            SqlDataAdapter da = new SqlDataAdapter("SELECT '' AS MA_GV, '' AS TEN_GV FROM GIAO_VIEN UNION SELECT MA_GV, TEN_GV FROM GIAO_VIEN", database.conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            database.Close();
            return dt;
        }
        public bool themLop(string malop, string tenlop, string magv, int siso)
        {
            database.Open();
            string them = "insert into LOP values('" + malop + "', '" + magv + "',N'" + tenlop + "', '" + siso + "')";
            cmd = new SqlCommand(them, database.conn);
            cmd.ExecuteNonQuery();
            MessageBox.Show("Thêm Lớp thành công!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            database.Close();
            return true;
        }
        public bool suaLop(string malop, string tenlop, string magv, int siso)
        {
            database.Open();
            string sua = "update LOP set MA_GV='" + magv + "',TEN_LOP=N'" + tenlop + "',SI_SO='" + siso + "' where MA_LOP='" + malop + "'";
            cmd = new SqlCommand(sua, database.conn);
            cmd.ExecuteNonQuery();
            MessageBox.Show("Cập nhật Lớp thành công!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            database.Close();
            return true;
        }
        public bool xoaLop(string malop)
        {
            database.Open();
            string xoa = "delete LOP where MA_LOP='" + malop + "'";
            cmd = new SqlCommand(xoa, database.conn);
            cmd.ExecuteNonQuery();
            MessageBox.Show("Xóa Lớp thành công!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            database.Close();
            return true;
        }
    }
}
